package com.lolc.utils;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import com.lolc.LoLAutoCounterManager;

public class Constant {
	
	public final static String CONFIG_FILE					= "./config/configuration.properties";
	public final static String SOURCE_URL_PROPERTY 		   	= "champions.list.url";
	public final static String NUMBER_SYNERGIES_PROPERTY  	= "number.synergies";
	public final static String NUMBER_COUNTERS_PROPERTY   	= "number.counters";
	public final static String NUMBER_CHAMPIONS_PROPERTY  	= "number.champions";
	public final static String CHAMPIONS_XML_FILE_PATH_PROPERTY = "champions.list.xml.file";
	public final static String HTTP_PROXY_HOST_PROPPERTY	= "http.proxy.host";
	public final static String HTTP_PROXY_PORT_PROPERTY 	= "http.proxy.port";
	public final static String LANES_XML_FILE_PATH_PROPERTY = "lanes.list.xml.file";
	public final static String SOURCE_URL_LOCAL_PROPERTY 	= "champions.list.url.local";
	
	public static int NUMBER_SYNERGIES;
	public static int NUMBER_COUNTERS;
	public static int NUMBER_CHAMPIONS;
	public static String SOURCE_URL;
	public static boolean SOURCE_URL_IS_LOCAL;
	public static String CHAMPIONS_XML_FILE;
	public static String LANES_XML_FILE;
	public static String HTTP_PROXY_HOST;
	public static String HTTP_PROXY_PORT;
	
	public final static int NUMBER_BANNED_CHAMPIONS_PER_TEAM=3;
	public final static int NUMBER_PLAYER_PER_TEAM=5;
	
	/**
	 * XML Element
	 */
	public final static String XML_FILE_CHAMPIONS_ELEMENT="champions";
	public final static String XML_FILE_CHAMPION_ELEMENT="champion";
	public final static String XML_FILE_COUNTERS_ELEMENT="counters";
	public final static String XML_FILE_COUNTER_ELEMENT="counter";
	public final static String XML_FILE_SYNERGIES_ELEMENT="synergies";
	public final static String XML_FILE_SYNERGIE_ELEMENT="synergie";
	public final static String XML_FILE_ID_ATTRIBUTE="id";
	public final static String XML_FILE_NAME_ATTRIBUTE="name";
	public final static String XML_FILE_CHAMPIONID_ATTRIBUTE="championid";
	public final static String XML_FILE_RATIO_ATTRIBUTE="ratio";
	public final static String XML_FILE_LOAD_DATE_ATTRIBUTE="refresh-date";

	public final static String XML_FILE_LANES_ELEMENT="lanes";
	public final static String XML_FILE_LANE_ELEMENT="lane";
	public final static String XML_FILE_TYPE_ATTRIBUTE="type";
	
	
	/**
	 * Regular expression for champion info
	 */
	public static final String JUNGLER_HTML_REGEXP = "<span class=\"label tag_jungler\">(.*?)</span>";
	public static final String TOP_HTML_REGEXP = "<span class=\"label tag_top\">(.*?)</span>";
	public static final String MID_HTML_REGEXP = "<span class=\"label tag_mid\">(.*?)</span>";
	public static final String BOTTOM_HTML_REGEXP = "<span class=\"label tag_bottom\">(.*?)</span>";
	
	/**
	 * Message
	 */
	public static final String MESSAGE_KEY_GET_CHAMPIONS="msg.get.champions.list";
	public static final String MESSAGE_KEY_SAVE_XML_FILE="msg.save.xml.file";
	public static final String MESSAGE_KEY_XML_FILE_SAVED="msg.xml.file.saved";
	public static final String MESSAGE_KEY_GET_CHAMPIONS_INTERACTIONS="msg.get.champions.interactions";
	public static final String MESSAGE_KEY_GET_CHAMPION_INTERACTIONS="msg.get.champion.interactions";
	public static final String MESSAGE_KEY_ERROR="msg.error.occured";
	
	static
	{
		Properties prop = new Properties();
		InputStream in;
		try {
			in = new FileInputStream(CONFIG_FILE);
			prop.load(in);
			SOURCE_URL = prop.getProperty(SOURCE_URL_PROPERTY);
			CHAMPIONS_XML_FILE = prop.getProperty(CHAMPIONS_XML_FILE_PATH_PROPERTY);
			LANES_XML_FILE = prop.getProperty(LANES_XML_FILE_PATH_PROPERTY);
			NUMBER_SYNERGIES = Integer.parseInt(prop.getProperty(NUMBER_SYNERGIES_PROPERTY));
			NUMBER_COUNTERS = Integer.parseInt(prop.getProperty(NUMBER_COUNTERS_PROPERTY));
			NUMBER_CHAMPIONS= Integer.parseInt(prop.getProperty(NUMBER_CHAMPIONS_PROPERTY));
			SOURCE_URL_IS_LOCAL="true".equalsIgnoreCase(prop.getProperty(SOURCE_URL_LOCAL_PROPERTY));
			
			if (prop.getProperty(HTTP_PROXY_HOST_PROPPERTY)!=null && !("".equals(prop.getProperty(HTTP_PROXY_HOST_PROPPERTY).trim())))
			{
				HTTP_PROXY_HOST=prop.getProperty(HTTP_PROXY_HOST_PROPPERTY);
			}
			
			if (prop.getProperty(HTTP_PROXY_PORT_PROPERTY)!=null && !("".equals(prop.getProperty(HTTP_PROXY_PORT_PROPERTY).trim())))
			{
				HTTP_PROXY_PORT=prop.getProperty(HTTP_PROXY_PORT_PROPERTY);
			}
			
			in.close();
		} 
		catch (IOException e) {
			// TODO Auto-generated catch block
			LoLAutoCounterManager.getLogger().error(e.getCause());
		}
	}
}
